﻿using Prism.Events;
using Prism.Mvvm;
using System.Windows;
using System.Windows.Media;

namespace MaterialTypeRecognition.Shell.ViewModels
{
    internal class TipWindowMessageModel
    {
        /// <summary>
        /// 窗口内容。
        /// </summary>
        public string? Content { get; set; }

        /// <summary>
        /// 窗口画刷。
        /// </summary>
        public Brush? WindowBrush { get; set; }
    }

    public class TopTipWindowViewModel : BindableBase
    {
        public TopTipWindowViewModel(IEventAggregator eventAggregator)
        {
            eventAggregator.GetEvent<PubSubEvent<TipWindowMessageModel>>().Subscribe((model) =>
            {
                WindowBrush = model.WindowBrush;
                Content = model.Content;
            });

            WindowBrush = Brushes.Gray;
            Content = "未进行分类";
        }

        public Window OwnerWindow = null!;

        private Brush? _windowBrush;

        /// <summary>
        /// 窗口画刷。
        /// </summary>
        public Brush? WindowBrush
        {
            get => _windowBrush;
            set
            {
                SetProperty(ref _windowBrush, value);
            }
        }

        private string _content = string.Empty;

        /// <summary>
        /// 窗口内容。
        /// </summary>
        public string? Content
        {
            get => _content;
            set
            {
                SetProperty<string>(ref _content, value ?? string.Empty);
            }
        }

        private bool _isLeft;

        public bool IsLeft
        {
            get => _isLeft;
        }


        public void ShowLeft()
        {
            _isLeft = true;
            if (OwnerWindow.Visibility != Visibility.Visible)
            {
                OwnerWindow.Visibility = Visibility.Visible;
            }

            OwnerWindow.Left = 0;
            OwnerWindow.Top = 0;
        }

        public void ShowRight()
        {
            _isLeft = false;
            if (OwnerWindow.Visibility != Visibility.Visible)
            {
                OwnerWindow.Visibility = Visibility.Visible;
            }

            var width = SystemParameters.WorkArea.Size.Width;
            var left = width - OwnerWindow.Width;
            OwnerWindow.Top = 0;
            OwnerWindow.Left = left < 0 ? 0 : left;
        }

        public void Hide()
        {
            OwnerWindow.Visibility = Visibility.Hidden;
        }
    }
}
